/*
//              INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license  agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in  accordance  with the terms of that agreement.
//    Copyright (c) 2003-2007 Intel Corporation. All Rights Reserved.
//
//
*/

#include "umc_defs.h"
#if defined (UMC_ENABLE_DV_VIDEO_DECODER)

#include <ippvc.h>
#include "umc_dv_decoder.h"
#include "umc_dv_internal.h"

namespace UMC
{

void DVVideoDecoder::HuffmanDecodeSegment_DV_DC_only(Ipp8u *lpbSource, Ipp16u *lpsDest)
{
    Ipp32s l;

    for (l = 0;l < 5;l += 1)
    {
        // y0
        lpsDest[0] = *(reinterpret_cast<Ipp8s *> (lpbSource + 4 + 14 * 0 + 10 * 0));
        lpsDest += 64;

        // y1
        lpsDest[0] = *(reinterpret_cast<Ipp8s *> (lpbSource + 4 + 14 * 1 + 10 * 0));
        lpsDest += 64;

        // y2
        lpsDest[0] = *(reinterpret_cast<Ipp8s *> (lpbSource + 4 + 14 * 2 + 10 * 0));
        lpsDest += 64;

        // y3
        lpsDest[0] = *(reinterpret_cast<Ipp8s *> (lpbSource + 4 + 14 * 3 + 10 * 0));
        lpsDest += 64;

        // cr
        lpsDest[0] = *(reinterpret_cast<Ipp8s *> (lpbSource + 4 + 14 * 4 + 10 * 0));
        lpsDest += 64;

        // cb
        lpsDest[0] = *(reinterpret_cast<Ipp8s *> (lpbSource + 4 + 14 * 4 + 10 * 1));
        lpsDest += 64;

        lpbSource += 4 + 14 * 4 + 10 * 2;
    };

} // void DVVideoDecoder::HuffmanDecodeSegment_DV_DC_only(Ipp8u *lpbSource, Ipp16u *lpsDest)

void DVVideoDecoder::StoreDVSDSegment_8s(Ipp32u i, Ipp32u k, Ipp32u nThreadNum)
{
    STORE_DV_SEGMENT_INFO RealStoreInfo;

    // reset pointers
    InitializeStoreDVSDInfo(RealStoreInfo, i, k, nThreadNum);

    // Store system 525 DV segment
    if (SYSTEM_525 == m_nSystem)
    {
        if (24 <= k)
        {
            ippiYCrCb411ToYCbCr422_ZoomOut8_EdgeDV_16s8u_P3C2R((Ipp16s *) RealStoreInfo.m_lpsSource[4],
                                                               RealStoreInfo.m_lpbDestination[4],
                                                               (Ipp32u) RealStoreInfo.m_lPitch);

            RealStoreInfo.m_lpbDestination[4] = NULL;
            RealStoreInfo.m_lpsSource[4] = NULL;
        }

        ippiYCrCb411ToYCbCr422_ZoomOut8_5MBDV_16s8u_P3C2R((const Ipp16s **) RealStoreInfo.m_lpsSource,
                                                          RealStoreInfo.m_lpbDestination);
    }
    else
    {
        ippiYCrCb420ToYCbCr422_ZoomOut8_5MBDV_16s8u_P3C2R((const Ipp16s **) RealStoreInfo.m_lpsSource,
                                                          RealStoreInfo.m_lpbDestination,
                                                          (Ipp32u) RealStoreInfo.m_lPitch);
    }

} // void DVVideoDecoder::StoreDVSDSegment_8s(Ipp32u i, Ipp32u k, Ipp32u nThreadNum)

void DVVideoDecoder::StoreDV25Segment_8s(Ipp32u i, Ipp32u k, Ipp32u nThreadNum)
{
    STORE_DV_SEGMENT_INFO RealStoreInfo;

    // reset pointers
    InitializeStoreDV25Info(RealStoreInfo, i, k, nThreadNum);

    // Store system 525 DV segment (system 625 has equal storing structure)
    if (24 <= k)
    {
        ippiYCrCb411ToYCbCr422_ZoomOut8_EdgeDV_16s8u_P3C2R((Ipp16s *) RealStoreInfo.m_lpsSource[4],
                                                           RealStoreInfo.m_lpbDestination[4],
                                                           (Ipp32u) RealStoreInfo.m_lPitch);

        RealStoreInfo.m_lpbDestination[4] = NULL;
        RealStoreInfo.m_lpsSource[4] = NULL;
    }

    ippiYCrCb411ToYCbCr422_ZoomOut8_5MBDV_16s8u_P3C2R((const Ipp16s **) RealStoreInfo.m_lpsSource,
                                                      RealStoreInfo.m_lpbDestination);

} // void DVVideoDecoder::StoreDV25Segment_8s(Ipp32u i, Ipp32u k, Ipp32u nThreadNum)

} // end namespace UMC

#endif //(UMC_ENABLE_DV_VIDEO_DECODER)
